package com.xsherl.leetcode.solution;

import com.xsherl.leetcode.base.TreeNode;

public class PathSum {

    public boolean hasPathSum(TreeNode root, int targetSum) {
        if (root == null){
            return false;
        }
        targetSum -= root.val;
        if (root.left == null && root.right == null){
            return targetSum == 0;
        }
        return hasPathSum(root.left, targetSum) || hasPathSum(root.right, targetSum);
    }

    public static void main(String[] args) {
        TreeNode root = TreeNode.buildTree(5,4,8,11,null,13,4,7,2,null,null,null,1);
        int target = 22;
        boolean b = new PathSum().hasPathSum(root, target);
        System.out.println(b);
    }
}
